<template>
  <view class="haobei">
    <dao title="饭量" />
    <view style="width: 200rpx; height: 200rpx"></view>
    <view
      style="
        font-size: 42rpx;
        font-weight: 700;

        margin-bottom: 180rpx;
        text-align: center;
      "
      >饭量调整</view
    >
    <view
      style="
        margin-top: 40rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
      "
      v-for="(item, index) in itemss.data"
      :key="index"
    >
      <uni-number-box
        width="250"
        background="#21afff"
        color="#fff"
        :max="1000"
        v-model="itemss.data[index]"
        :step="step"
      />
    </view>

    <view class="weitao">
      <checkbox-group @change="weito">
        <label>
          <!-- <view style="display: flex; align-items: center">
            <checkbox
              value="cb"
              color="#21afff"
              style="transform: scale(0.7)"
            />
            微调
          </view> -->
        </label>
      </checkbox-group>
    </view>

    <button
      @click="baocu"
      style="background-color: #21afff; margin-top: 100rpx"
      type="primary"
    >
      保存设置
    </button>
  </view>
</template>

<script setup >
import dao from "../../pages/conpments/daohang.vue";

import { dafanti } from "../../api/login";

import {
  ref,
  onMounted,
  inject,
  getCurrentInstance,
  reactive,
  computed,
} from "vue";

const itemss = reactive({
  data: [1, 2, 3, 4, 5, 5],
});
let tyijaopshuju = ref({
  Id: null,
  RxControl: null,
  MealsWeight: null,
  MealsWeightConfig: null,
  Mode: null,
});

onMounted(() => {
  const instance = getCurrentInstance().proxy;
  const eventChannel = instance.getOpenerEventChannel();

  eventChannel.on("acceptDataFromOpenerPage", function (data) {
    itemss.data = data.data;
    tyijaopshuju.value.MealsWeight = itemss.data[0];
    tyijaopshuju.value.Id = data.id;
  });
});

const baocu = async () => {
  tyijaopshuju.value.MealsWeight = null;
  tyijaopshuju.value.RxControl = 2;

  tyijaopshuju.value.MealsWeightConfig = itemss.data;

  const { data } = await dafanti(tyijaopshuju.value);
  if (data.code) {
    uni.setStorage({
      key: "mo",
      data: itemss.data,
      success: function () {
        uni.showToast({
          title: "设置成功！",
          icon: "success",
          duration: 500,
        });
      },
    });
  } else {
  }
};
</script>

<style scoped lang="scss" >
.yang {
  height: 100rpx;
}

.fanhuis {
  padding: 0 20rpx;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 50rpx;
  .title {
    font-weight: 700;
    font-size: 32rpx;
  }
}
.shig {
  color: #999;
  margin: 100rpx 0;
}
.JIANBAIN {
  height: 100vh;
  background: linear-gradient(to bottom, #b8dcfc 0%, #eef7ff 20%, #fff 100%);
}
.tosus {
  width: 100%;
  display: flex;
  align-items: center;
  font-size: 16px;
  justify-content: center;
  font-weight: 700;
  text-align: center;
}
.biaozn {
  text-align: center;
  font-size: 40rpx;
  color: #3a3a3a;
  font-weight: 700;
  margin-bottom: 30rpx;
}

.kuanvox {
  width: 100%;
  height: 500rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.nit {
  color: #999;
}

.weitiao {
  margin-top: 30rpx;
  display: flex;
  flex-direction: row-reverse;
  color: #21afff;
  margin-right: 20rpx;
}
.xuabn {
  width: 90vw;
  height: 80rpx;
  display: flex;
  justify-content: space-between;
  color: #fff;
  font-size: 32rpx;
  align-items: center;
  box-shadow: 0 1px 10px 1px rgba(0, 0, 0, 0.2);

  padding: 0 10rpx;
  margin: 40rpx auto;
  border-radius: 80rpx;
  background: #21afff;
  .xu {
    width: 33%;
    text-align: center;
    height: 70rpx;
    border-radius: 70rpx;
    font-weight: 700;
    line-height: 70rpx;
  }
  .sd {
    background: #fff;
    color: #6a6a6a;
  }
}

.weitao {
  text-align: right;
  margin-top: 50rpx;
  font-size: 24rpx;
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
  color: #909399;
}
</style>